<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8"/>
    <title>后台管理系统</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta
            name="viewport"
            content="width=device-width, initial-scale=1, maximum-scale=1"
    />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
    <link rel="stylesheet" href="sdk/sdk.css"/>
    <link rel="stylesheet" href="sdk/helper.css"/>
    <link rel="stylesheet" href="sdk/iconfont.css"/>

    <style>
        html,
        body,
        .app-wrapper {
            position: relative;
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
        }
    </style>
</head>
<body>
<div id="root" class="app-wrapper"></div>
<script src="sdk/sdk.js"></script>
<script type="text/javascript">
    (function () {
        let amis = amisRequire('amis/embed');
        // 通过替换下面这个配置来生成不同页面
        let amisJSON = {
            type: 'page',
            title: '登录后台管理系统',
            body: {
                type: 'form',
                mode: 'horizontal',
                api: {
                     url: '/api/user/login',
                    method: 'post',
                    adaptor: function (payload, response) {

                         // console.log(payload.data)
                        if (payload.status === 0) {
                            let newDate = new Date();//获取当前的时间对象
                            let nowTimeStamp = newDate.getTime();//获取当前时间对象的时间戳
                            nowTimeStamp += (3600);
                            newDate.setTime(nowTimeStamp);
                            let expires = "expires=" + newDate.toGMTString();
                            document.cookie = `username=${payload.data.username};${expires}`;
                        }
                        return payload
                    },
                },
                redirect: "/",
                body: [
                    {
                        label: '用户名',
                        type: 'input-text',
                        name: 'user_name'
                    },
                    {
                        label: '密码',
                        type: 'input-password',
                        name: 'user_pass'
                    }
                ]
            }
        };
        let amisScoped = amis.embed('#root', amisJSON);
    })();
</script>
</body>
</html>